package com.xlh.server.protocol.support.json;

import com.xlh.Utils.GsonManager;
import com.xlh.Utils.MudProtocol;
import com.xlh.bean.ProBean;
import com.xlh.bean.ProtocolObject.EnvObjectsStateAttr;
import com.xlh.bean.ProtocolObject.HpInfo;
import com.xlh.interf.IActivity;
import com.xlh.interf.ITakeMessage;
import com.xlh.outside.MainActivity;
import com.xlh.outside.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 环境中对象的属性
 * Created by mike@Q184377367 on 2018/7/2.
 */

public class EnvObjectsStateAttrServer implements ITakeMessage {

    private IActivity atv;
    private String hasType = "envObjectsStateAttr";
    private EnvObjectsStateAttr protccoObj;

    public EnvObjectsStateAttrServer(IActivity atv){
        this.atv = atv;


    }

    @Override
    public void takeMessage(String t,String s){

        if(!t.equals(this.hasType)) return;

        protccoObj =  GsonManager.gsmgr.jsonToAnyObject(s, EnvObjectsStateAttr.class);

        if(protccoObj==null) return;
        this.renderView();

    }

    public void renderView(){
        final EnvObjectsStateAttrServer me = this;

        ProBean p = new ProBean();
        p.setMin(this.protccoObj.getState().getMin());
        p.setMax(this.protccoObj.getState().getMax());
        p.setAction(this.protccoObj.getState().getSecId());

        if( this.atv.getActivity().mTitleAdapter.getCount() > 0 ){
            String ac1,ac2;
            for(int i=0;i<this.atv.getActivity().mTitleAdapter.getCount();i++){
                ac1 = this.atv.getActivity().mTitleAdapter.getItem(i).getmAction();
                if(  ac1==null || !ac1.contains("/")  ) continue;

                ac1 = ac1.substring(ac1.indexOf("/"),ac1.length());
                if( ac1.equals(p.getAction()) ){
                    this.atv.getActivity().mTitleAdapter.updateProgress(i,p);
                }

            }


        }
    }


    @Override
    public boolean takeMessage(String s) {
        return false;
    }

    @Override
    public void init() {

    }

    @Override
    public void atViewLoadAfterInit() {

    }

}
